home *** CD-ROM | disk | FTP | other *** search
- { jaggies.pas -- Draw jagged lines }
-
- program Jaggies;
-
- uses WinTypes, WinProcs, WObjects;
-
- type
-
- GrApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PGraphWindow = ^GraphWindow;
- GraphWindow = object(TWindow)
- ButtonDown : Boolean;
- Dc : HDC;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- function GetClassName: PChar;
- virtual;
- procedure GetWindowClass(var AWndClass: TWndClass);
- virtual;
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- procedure WMLButtonUp(var Msg: TMessage);
- virtual wm_First + wm_LButtonUp;
- procedure WMMouseMove(var Msg: TMessage);
- virtual wm_First + wm_MouseMove;
- procedure WMLButtonDblClk(var Msg: TMessage);
- virtual wm_First + wm_LButtonDblClk;
- end;
-
- { GrApplication }
-
- {- Initialize the application's window }
- procedure GrApplication.InitMainWindow;
- begin
- MainWindow := New(PGraphWindow,
- Init(nil, 'Jaggies -- Double click to clear'))
- end;
-
- { GraphWindow }
-
- {- Initialize a GraphWindow object }
- constructor GraphWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- ButtonDown := false
- end;
-
- {- Return class name for modified window class }
- function GraphWindow.GetClassName: PChar;
- begin
- GetClassName := 'GraphWindow'
- end;
-
- {- Modify window style to recognize double clicks }
- procedure GraphWindow.GetWindowClass(var AWndClass: TWndClass);
- begin
- TWindow.GetWindowClass(AWndClass);
- AWndClass.Style := AWndClass.Style or cs_DblClks
- end;
-
- {- Respond to left-button-down mouse clicks }
- procedure GraphWindow.WMLButtonDown(var Msg: TMessage);
- begin
- if not ButtonDown then
- begin
- ButtonDown := true;
- SetCapture(HWindow);
- Dc := GetDC(HWindow);
- MoveTo(Dc, Msg.LParamLo, Msg.LParamHi)
- end
- end;
-
- {- Respond to left-button-up mouse clicks }
- procedure GraphWindow.WMLButtonUp(var Msg: TMessage);
- begin
- if ButtonDown then
- begin
- ReleaseCapture;
- ReleaseDC(HWindow, Dc);
- ButtonDown := False
- end
- end;
-
- {- Respond to mouse movements }
- procedure GraphWindow.WMMouseMove(var Msg: TMessage);
- begin
- if ButtonDown then with Msg do
- begin
- LineTo(Dc, LParamLo, LParamHi);
- LineTo(Dc, LParamLo - 4, LParamHi + 4)
- end
- end;
-
- {- Respond to left-button double clicks }
- procedure GraphWindow.WMLButtonDblClk(var Msg: TMessage);
- begin
- InvalidateRect(HWindow, nil, true)
- end;
-
- var
-
- GrApp: GrApplication;
-
- begin
- GrApp.Init('GrApp');
- GrApp.Run;
- GrApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 1/30/1991
- ---------------------------------------------------------------}
-